package com.woniuxy.ui;

import com.woniuxy.entity.Student;
import com.woniuxy.service.StudentService;
import com.woniuxy.service.impl.StudentServiceImpl;

import java.util.Scanner;

/**
 * @author 作者
 * @create 2025-08-05 9:57
 */
public class StartMenu {

    static StudentService studentService=new StudentServiceImpl();

    public static void login(){
        Scanner sc = new Scanner(System.in);
        System.out.println("输入用户名");
        String uname = sc.next();
        System.out.println("输入密码");
        String password = sc.next();
        try{
            studentService.login(uname,password);
            //登录成功，进入主菜单
            Application.showMainMenu();
        }catch (Exception e){
            //登录失败，进入开始菜单
            e.printStackTrace();
            System.out.println(e.getMessage());
            Application.showStartMenu();
        }
    }
    public static void regist(){
        Scanner sc = new Scanner(System.in);
        System.out.println("输入用户名");
        String sname = sc.next();
        System.out.println("输入密码");
        String password = sc.next();
        System.out.println("输入年龄");
        int age = sc.nextInt();
        System.out.println("输入邮箱");
        String email = sc.next();
        Student student=new Student(null, sname, password, age, email);
        try{
            studentService.regist(student);
        }catch (Exception e){
            //登录失败，进入开始菜单
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
        Application.showStartMenu();
    }

}
